<?php

declare(strict_types=1);

namespace app\middleware;

use app\facade\Token;
use app\model\Users;

class AuthCheck
{
    /**
     * 处理请求
     *
     */
    public function handle($request, \Closure $next)
    {
        //判断头部是否有token
        $jwt = $request->header('Authorization');
        if (empty($jwt)) {
            return rejson(0, null, $msg = "请登录", 401);
        };
        //判断token是否过期
        $resData = Token::getTokenData($jwt);
        if (!$resData) {
            return rejson(0, null, '请登录', 401);
        }
        return $next($request);
    }
}
